package day9;

import java.sql.*;
import java.util.Scanner;

public class QueryProject {
    //根据编号修改user信息
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        String url = "jdbc:mysql://localhost:3308/fuyang?autoReconnect=true&useUnicode=true&characterEncoding=utf8" +
                "&serverTimezone=GMT%2B8";
        String user = "root";
        String pass = "root1234";
        Connection con = null;
        PreparedStatement st = null;
        ResultSet rs=null;
        Scanner in = new Scanner(System.in);
        System.out.print("请输入项目名称：");
        String pname=in.next();

        try {
            con = DriverManager.getConnection(url, user, pass);
            String sql="select * from project where projectname like ?";

            st=con.prepareStatement(sql);
            st.setString(1,"%"+pname+"%");
             rs=st.executeQuery();
            while (rs.next()){
                System.out.println(rs.getLong("id"));
                System.out.println(rs.getString("projectname"));
                System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                st.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                con.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
